<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentTopicList.class.php, $Author:  $ */



/** Forum topics list componment
 *
 * 1. oUser (optional) - current user; for visitor - null or omitted
 *
 * @package module.forum
 * @version $Id: PhpFox_ComponentTopicList.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Forum_ComponentTopicList extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
        $oSrvSec = &App::getModuleService('Account', 'Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        $oSrvSec->checkPerm('forum', array('read_only', 'full'));

	    $oReq = &App::getRequest();
	    /* @var $oReq Request */

	    $oSrvForum = &$this->_oModule->getService('Forum');
	    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */

	    //get current user
	    $oUser = $this->getParam('oUser', null);
    	$sUser = $oUser ? $oUser->aData['user'] : '';

		$iPage = $oReq->getInt('page', 1);
    	$iPageSize = App::getParam('public.pagesize');

    	$iForumId = $oReq->getInt('id');
    	$oForum = $this->_oModule->getItem('Forum');
    	if (! ($iForumId && $oForum->load($iForumId)))
    	{
    	    App::gotoUrl('public.forum');
    	}

        $aCond = array('type'=>' = '.$iForumId);

	    list($aTopics, $iTotal) = $oSrvForum->getTopicsList($aCond, $iPage, $iPageSize, 'last_time DESC', $sUser);

        $oPager = App::newObject('Pager', $iTotal, $iPage, $iPageSize);

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
            	'aTopics'     => $aTopics,
		    	'sUserPicUrl' => App::getParam('user.pic.url'),
	        	'aPaging'     => $oPager->getInfo(App::getUrl()),
		    	'bIsGuest'    => ! $oUser,
            	'dtToday'     => time(),
		    	'iThreadId'   => $iForumId,
		    	'iAnnounce'   => App::getParam('Mod_Forum.type.announcement'),
		    	'iSticky'     => App::getParam('Mod_Forum.type.sticky'),
		));
		$srcHtml = $oTpl->fetch('TopicList.html');
		return $srcHtml;
	}

}
?>